package mao.leetcode.others.leetcode129;


/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    int sum;
    int number;
    public int sumNumbers(TreeNode root) {
        if (root == null) return 0;
        number=number*10+root.val;
        if (root.left == null && root.right == null){
            sum+=number;
        }else {
            sumNumbers(root.left);
            sumNumbers(root.right);
        }
        number/=10;
        return sum;
    }


    public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }
}
